<?php

/**
 * reserva2 actions.
 *
 * @package    gestdent
 * @subpackage reserva2
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class reserva2Actions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {

      //LISTADO DE HORAS
      $this->gestdent_hora_list = GestdentHoraPeer::doSelect(new Criteria());

      //QUERY PARA LISTADO DE BOX
      $MyCriterioBox = new Criteria();
      $MyCriterioBox->add(GestdentBoxPeer::SUCURSAL,1);
      $this->gestdent_box_list = GestdentBoxPeer::doSelect($MyCriterioBox);

    $this->gestdent_reserva_list = GestdentReserva2Peer::doSelect(new Criteria());
    $this->formulario = new GestdentReserva2FormCustom();
  }

  public function executeFiltrar(sfWebRequest $request)
  {

      //LISTADO DE HORAS
      $this->gestdent_hora_list = GestdentHoraPeer::doSelect(new Criteria());

      //QUERY PARA LISTADO DE BOX
      $MyCriterioBox = new Criteria();
      $MyCriterioBox->add(GestdentBoxPeer::SUCURSAL,1);
      $this->gestdent_box_list = GestdentBoxPeer::doSelect($MyCriterioBox);

    $inicio = $request->getParameter('Desde');
    $fin = $request->getParameter('Hasta');

    $fecha = $request->getParameter('Fecha');


    //$this->gestdent_reserva_list = GestdentReserva2Peer::filtrado($inicio['year']."-".$inicio['month']."-".$inicio['day'], $fin['year']."-".$fin['month']."-".$fin['day']);
    $this->gestdent_reserva_list = GestdentReserva2Peer::filtrar($fecha['year']."-".$fecha['month']."-".$fecha['day']);

    $this->setTemplate('index');
    //$this->formulario = new FiltroForm();
    $this->formulario = new GestdentReserva2FormCustom();
    $this->getUser()->setAttribute('valor', $this->gestdent_reserva_list);
    
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->gestdent_reserva2 = GestdentReserva2Peer::retrieveByPk($request->getParameter('id'));
    $this->forward404Unless($this->gestdent_reserva2);
  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new GestdentReserva2Form();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post'));

    $this->form = new GestdentReserva2Form();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($gestdent_reserva2 = GestdentReserva2Peer::retrieveByPk($request->getParameter('id')), sprintf('Object gestdent_reserva2 does not exist (%s).', $request->getParameter('id')));
    $this->form = new GestdentReserva2Form($gestdent_reserva2);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post') || $request->isMethod('put'));
    $this->forward404Unless($gestdent_reserva2 = GestdentReserva2Peer::retrieveByPk($request->getParameter('id')), sprintf('Object gestdent_reserva2 does not exist (%s).', $request->getParameter('id')));
    $this->form = new GestdentReserva2Form($gestdent_reserva2);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($gestdent_reserva2 = GestdentReserva2Peer::retrieveByPk($request->getParameter('id')), sprintf('Object gestdent_reserva2 does not exist (%s).', $request->getParameter('id')));
    $gestdent_reserva2->delete();

    $this->redirect('reserva2/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $gestdent_reserva2 = $form->save();

      $this->redirect('reserva2/edit?id='.$gestdent_reserva2->getId());
    }
  }
}
